home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / msdos / raytrace / pov / gen / bstone / borlandc / t_lex.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-21  |  10.3 KB  |  362 lines

  1. /*********************************************************************/
  2. /*   Header declarations of lex function and related stuff           */
  3. /* + Keywords consist of letters,digits and _ , first char must be   */
  4. /*   a letter                                                        */
  5. /* + Permits forcing of expected types                               */
  6. /* + Eliminates c style  comments                                    */
  7. /*********************************************************************/
  8.  
  9. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  10. /* include the yacc header file (use yacc -d)                        */
  11. /* for definition of tokens                                          */
  12. /* #include "y.tab.h"                                                */
  13. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  14.  
  15.  
  16. /*********************************************************************/
  17. /**** Lex-functions **************************************************/
  18. /*********************************************************************/
  19. /* Lex-struct consists of object type and object value               */
  20. /* object type: int                                                  */
  21. /* object value will be stored as a struct:                          */
  22. /* either real or int number (union: wert.n.r, wert.n.i)             */
  23. /* or pointer to char-field  (wert.c) of length LEX_MAXWERT          */
  24. /* file end is: type "EOLX" (-1)                                     */
  25.  
  26. #define LEX_MAXWERT 256
  27.  
  28. typedef struct {
  29.                 int typ;
  30.                 struct {
  31.                         char *c;
  32.             union {
  33.                    int  i;
  34.                    double r;
  35.                   } n;
  36.                        } wert;
  37.                } LEX;
  38.  
  39.  
  40. /* Lex-function: parameter: fep: pointer to readable file            */
  41. /*                          force: force expected type               */
  42. /* if fep==NULL then it will ask t_setfep                            */
  43. /* use "t_lex(fep,NO_FORCE)" for unforced lex                        */
  44. /*               returns: pointer to t_lexx or NULL,                 */
  45. /*               if syntax error                                     */
  46. LEX *t_lex(FILE *fep,int force);
  47.  
  48.  
  49. /* function for setting filepointer and flags                        */
  50. /* returns current filepointer, if fep==NULL;                        */
  51. /* else sets and returns current filepointer                         */
  52. /* Flags: Bit 0: return EOLN, for line-sensitive syntax              */
  53. /*        Bit 1: case-insensitive                                    */
  54. FILE *t_setfep(FILE *fep, long flags);
  55.  
  56.  
  57. /* returns string for error message                                  */
  58. /* this string has got ca. 80 chars reserved for your own purpose    */
  59. char *t_pos(void);
  60.  
  61. /*********************************************************************/
  62. /**** Symbol table ***************************************************/
  63. /*********************************************************************/
  64. typedef struct t_node {
  65.                char *s;                       /* name            */
  66.                int   n;                       /* number          */
  67.                struct t_node *l;              /* left branch     */
  68.                struct t_node *r;              /* right branch    */
  69.                struct t_node *nl;             /* next element    */
  70.                struct t_node *a;              /* alias           */
  71.                void *p;                       /* for users purp. */
  72.                int c;                         /* user code       */
  73.               } T_NODE;
  74.  
  75. /* simple symbol table manager, one symbol table only                    */
  76. /* input: string, returns: T_NODE-ptr, NULL on error                     */
  77. /* table contains any KW                                                 */
  78. T_NODE *t_symtable(char *str);
  79.  
  80. /* finds symbol n, returns T_NODE (NULL if error)                        */
  81. T_NODE *t_symfind(int n);
  82.  
  83. /* performs action on all items with code                                */
  84. /* if code <0, performs action on all items                              */
  85. /* action will get T_NODE                                                */
  86. /* returns: sum of action's returns                                      */
  87. int t_symwalk(int code, int (*action)(T_NODE *));
  88.  
  89. /* performs action on tnodes and deletes any tnode and any tnode->p      */
  90. /* returns number of deleted nodes                                       */
  91. int t_symdel(void (*action)(T_NODE *));
  92.  
  93. /*********************************************************************/
  94. /**** Associations ***************************************************/
  95. /*********************************************************************/
  96.  
  97. /* Association list:  type(num) <-> type(name)                        */
  98. /* Try to avoid confusion with tokens defined by yacc.                */
  99. #ifndef EOLX
  100. #define EOLX          (EOF)                 /* end of text            */
  101. #endif
  102. #ifndef EOLN
  103. #define EOLN          (-2)                  /* end of line            */
  104. #endif
  105. #ifndef ZAHL
  106. #define ZAHL          (-3)                  /* "number"               */
  107. #endif
  108. #ifndef REAL
  109. #define REAL          (-4)                  /* "real number"          */
  110. #endif
  111. #ifndef BEZEICHNER
  112. #define BEZEICHNER    (-5)                  /* "varname"              */
  113. #endif
  114.  
  115. /* internal associations, don't redefine                              */
  116.  
  117. #define KW            (-6)                       /* keyword = string  */
  118.        /* of letters,digit,_, 1.=letter, last may be any except space */
  119. #define LEX_UNDEF     (-7)                       /* undef char        */
  120. #define LEX_SPACE     (-8)                       /* elim space only   */
  121. #define LEX_COM       (-9)                       /* eliminates c-like */
  122.                          /* comments          */
  123. #define NO_FORCE      (-10)                      /* f:no force          */
  124. #define LEX_PUSH      (-11)                      /* f:push last expr.   */
  125. #define LEX_RCHAR     (-12)                      /* f:rec single char   */
  126.  
  127. /* returns number for tokentyp n                                          */
  128. int t_tokenval(int n);
  129. /* returns string for tokentyp n                                          */
  130. char *t_tokenstr(int n);
  131. /* returns tokentyp for number n                                          */
  132. int t_valtoken(int n);
  133. /* returns string for number n                                            */
  134. char *t_valstr(int n);
  135.  
  136. /* The Token used. TOKENSET contains the words, TOKENTYP the        */
  137. /* associated numbers. TOKENSET ends with "", TOKENTYP ends with    */
  138. /* the value associated to unrecognized words (eg. variable names)  */
  139. /* Use field initialization syntax.                                 */
  140.  
  141. #define END       257
  142. #define REM       258
  143. #define B_VAL     259 /* single value */
  144. #define B_VEC     260 /* vector */
  145. #define B_OBJ     261 /* visual object */
  146. #define GOTO      262
  147. #define ABS       263
  148. #define BEZ_VEC   264
  149. #define BEZ_OBJ   265
  150. #define TRACE     266
  151. #define LET       267
  152. #define PRINT     268
  153. #define LIST      269
  154. #define B_STR     270
  155. #define SCALE     271
  156. #define ROTATE    272
  157. #define TRANSLATE 273
  158. #define PI        274
  159. #define LOAD      275
  160. #define SAVE      276
  161. #define IF        277
  162. #define THEN      278
  163. #define STOP      279
  164. #define CONT      280
  165. #define GOSUB     281
  166. #define RETURN    282
  167. #define DELETE    283
  168. #define B_FLD     284    /* data field */
  169. #define B_NUM     285    /* number */
  170. #define DIM       286
  171. #define FOR       287
  172. #define TO        288
  173. #define STEP      289
  174. #define NEXT      290
  175. #define B_FOR     291 /* FOR-TO-LOOP */
  176. #define NEW       292
  177. #define RUN       293
  178. #define SIN       294
  179. #define COS       295
  180. #define TAN       296
  181. #define B_FKT     297 /* function */
  182. #define ASIN      298
  183. #define ACOS      299
  184. #define ATAN      300
  185. #define VX        301
  186. #define VY        302
  187. #define VZ        303
  188. #define EXP       304
  189. #define POW       305
  190. #define LOG       306
  191. #define SQRT      307
  192. #define ROT       308
  193. #define SCA       309
  194. #define RND       310
  195. #define FOPEN     311
  196. #define FPRINT    312
  197. #define V0        313
  198. #define CTDS      314
  199. #define PLANE     315
  200. #define BIT       316
  201. #define UNION     317
  202. #define SECT      318
  203. #define DIFF      319
  204. #define ADDOBJ    320
  205. #define TEX       321
  206. #define BOUND     322
  207. #define TRANSFORM 323
  208. #define SQR       324
  209. #define PER       325
  210.  
  211. #define TOKENSET {\
  212.           "END",\
  213.           "REM",\
  214.           "GOTO",\
  215.           " ",\
  216.           " ",\
  217.           " ",\
  218.           " ",\
  219.           " ",\
  220.           " ",\
  221.           " ",\
  222.           " ",\
  223.           "ABS",\
  224.           "^",\
  225.           "$",\
  226.           "TRACE",\
  227.           "LET",\
  228.           "PRINT",\
  229.           "LIST",\
  230.           "SCALE",\
  231.           "ROTATE",\
  232.           "TRANSLATE",\
  233.           "PI",\
  234.           "V0",\
  235.           "LOAD",\
  236.           "SAVE",\
  237.           "IF",\
  238.           "THEN",\
  239.           "STOP",\
  240.           "CONT",\
  241.           "GOSUB",\
  242.           "RETURN",\
  243.           "DELETE",\
  244.           "DIM",\
  245.           "FOR",\
  246.           "TO",\
  247.           "STEP",\
  248.           "NEXT",\
  249.           "NEW",\
  250.           "RUN",\
  251.           "SIN",\
  252.           "COS",\
  253.           "TAN",\
  254.           "ASIN",\
  255.           "ACOS",\
  256.           "ATAN",\
  257.           "VX",\
  258.           "VY",\
  259.           "VZ",\
  260.           "EXP",\
  261.           "POW",\
  262.           "LOG",\
  263.           "SQRT",\
  264.           "ROT",\
  265.           "SCA",\
  266.           "RND",\
  267.           "FOPEN",\
  268.           "FPRINT",\
  269.           "CTDS",\
  270.           "PLANE",\
  271.           "BIT",\
  272.           "UNION",\
  273.           "DIFF",\
  274.           "SECT",\
  275.           "ADDOBJ",\
  276.           "TEX",\
  277.           "BOUND",\
  278.           "TRANSFORM",\
  279.           "SQR",\
  280.           "PER",\
  281.           ""}
  282.  
  283. #define TOKENTYP {\
  284.           END,\
  285.           REM,\
  286.           GOTO,\
  287.           B_VAL,\
  288.           B_VEC,\
  289.           B_OBJ,\
  290.           B_STR,\
  291.           B_FLD,\
  292.           B_NUM,\
  293.           B_FOR,\
  294.           B_FKT,\
  295.           ABS,\
  296.           BEZ_VEC,\
  297.           BEZ_OBJ,\
  298.           TRACE,\
  299.           LET,\
  300.           PRINT,\
  301.           LIST,\
  302.           SCALE,\
  303.           ROTATE,\
  304.           TRANSLATE,\
  305.           PI,\
  306.           V0,\
  307.           LOAD,\
  308.           SAVE,\
  309.           IF,\
  310.           THEN,\
  311.           STOP,\
  312.           CONT,\
  313.           GOSUB,\
  314.           RETURN,\
  315.           DELETE,\
  316.           DIM,\
  317.           FOR,\
  318.           TO,\
  319.           STEP,\
  320.           NEXT,\
  321.           NEW,\
  322.           RUN,\
  323.           SIN,\
  324.           COS,\
  325.           TAN,\
  326.           ASIN,\
  327.           ACOS,\
  328.           ATAN,\
  329.           VX,\
  330.           VY,\
  331.           VZ,\
  332.           EXP,\
  333.           POW,\
  334.           LOG,\
  335.           SQRT,\
  336.           ROT,\
  337.           SCA,\
  338.           RND,\
  339.           FOPEN,\
  340.           FPRINT,\
  341.           CTDS,\
  342.           PLANE,\
  343.           BIT,\
  344.           UNION,\
  345.           DIFF,\
  346.           SECT,\
  347.           ADDOBJ,\
  348.           TEX,\
  349.           BOUND,\
  350.           TRANSFORM,\
  351.           SQR,\
  352.           PER,\
  353.           BEZEICHNER}
  354.  
  355.  
  356. /* value of single chars (from CHRSET) will be the char itself        */
  357. #ifndef CHRSET
  358. #define CHRSET        "+-*/<>=&|!,[]()#\"[]@%"
  359. #endif
  360.  
  361.  
  362.